app.service('DataService', function () {
    var arr = [];

    this.addItem = function (newItem) {

        var flag = false;
        arr.map(function (item) {
            if (item.id == newItem.id) {
                flag = true;
                item.count++;
            }
        })

        if (flag == false) { // 不存在
            newItem.count = 1;
            arr.push(newItem)
        }
    };

    this.reduce = function (index) {
        var item = arr[index];

        if (item.count == 1) {
            arr.splice(index, 1);
        } else {
            item.count --;
        }
    };

    this.getAllGoods = function () {
        return arr;
    };
});
